home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / pattern.c < prev    next >
C/C++ Source or Header  |  1993-09-02  |  9KB  |  369 lines

  1.  
  2.     /***********************************************
  3.     *
  4.     *    file d:\cips\pattern.c
  5.     *
  6.     *    Functions: This file contains
  7.     *       main
  8.     *
  9.     *    Purpose:
  10.     *       I use this program to create simple
  11.     *       patterns in images for illustrations.
  12.     *
  13.     *    External Calls:
  14.     *       gpcips.c - my_clear_text_screen
  15.     *       wtiff.c - create_allocate_tiff_file
  16.     *                 write_array_into_tiff_image
  17.     *
  18.     *    Modifications:
  19.     *       31 March 1991 - created
  20.     *       17 May 1993 - made this a command
  21.     *           line driven program.
  22.     *
  23.     ***********************************************/
  24.  
  25. #include "cips.h"
  26. #undef STUFF
  27.  
  28.  
  29. short p1[10][10] = 
  30.    {{11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  31.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  32.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  33.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  34.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  35.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  36.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  37.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  38.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  39.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11}};
  40.  
  41. short p2[10][10] = 
  42.    {{11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  43.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  44.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  45.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  46.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  47.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  48.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  49.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  50.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  51.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11}};
  52.  
  53.  
  54.  
  55.  
  56. short out_image[ROWS][COLS];
  57.  
  58. main(argc, argv)
  59.    int argc;
  60.    char *argv[];
  61. {
  62.    int      count, i, ie, ii, il, j, jj, le, l, ll,
  63.             new_ie, new_il, set_i, set_j, square_size, w;
  64.    struct   tiff_header_struct image_header;
  65.  
  66.  
  67.    my_clear_text_screen();
  68.  
  69.    if(argc < 4 ){
  70.       printf("\n usage: pattern file-name "
  71.              "length width\n"
  72.              "\n the program will multiply length "
  73.              "and width"
  74.              "\n by %d and %d", ROWS, COLS);
  75.       exit(-1);
  76.    }
  77.  
  78.    l = atoi(argv[2]);
  79.    w = atoi(argv[3]);
  80.  
  81.    image_header.lsb            = 1;
  82.    image_header.bits_per_pixel = 8;
  83.    image_header.image_length   = l*ROWS;
  84.    image_header.image_width    = w*COLS;;
  85.    image_header.strip_offset   = 1000;
  86.  
  87.    create_allocate_tiff_file(argv[1], &image_header, 
  88.                              out_image);
  89.  
  90.    new_ie = 1;
  91.    new_il = 1;
  92.    il     = 1;
  93.    ie     = 1;
  94.    ll     = ROWS+1;
  95.    le     = COLS+1;
  96.  
  97.    /********************************************/
  98.  
  99.  
  100.  
  101.       /* create a random image 100-150  */
  102.    for(i=0; i<ROWS; i++)
  103.       for(j=0; j<COLS; j++)
  104.         out_image[i][j] = 100 + (rand() %  25);
  105.  
  106.  
  107.  
  108.  
  109.    /********************************************/
  110.  
  111.    count = 1;
  112.    for(i=0; i<l; i++){
  113.       for(j=0; j<w; j++){
  114.          printf("\nRunning %d of %d", count, l*w);
  115.          count++;
  116.          write_array_into_tiff_image(argv[1], out_image,
  117.                          new_il + i*ROWS,
  118.                          new_ie + j*COLS,
  119.                          new_il + i*ROWS + ROWS,
  120.                          new_ie + j*COLS + COLS);
  121.       }
  122.    }
  123.  
  124. }  /* ends main */
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. #ifdef STUFF
  132.  
  133.  
  134. /*
  135.    The following are samples patterns you can stick
  136.    into the output image.
  137. */
  138.  
  139.  
  140.  
  141.  
  142.      /* make a step pattern of gray shades */
  143.    for(i=0; i<ROWS; i++)
  144.       for(j=0; j<COLS; j++)
  145.         out_image[i][j] = 0;
  146.    for(i=0; i<ROWS; i++)
  147.       for(j=10; j<20; j++)
  148.         out_image[i][j] = 5;
  149.    for(i=0; i<ROWS; i++)
  150.       for(j=20; j<30; j++)
  151.         out_image[i][j] = 10;
  152.    for(i=0; i<ROWS; i++)
  153.       for(j=30; j<40; j++)
  154.         out_image[i][j] = 20;
  155.  
  156.  
  157.      /*  make a club to look at thinning and mat */
  158.    for(i=0; i<ROWS; i++){
  159.       for(j=0; j<COLS; j++){
  160.         if( i>4 && i<11 && j>4 && j<17)
  161.           out_image[i][j] = 200;
  162.         else
  163.           out_image[i][j] = 0;
  164.     }
  165.    }
  166.    for(i=0; i<ROWS; i++){
  167.       for(j=0; j<COLS; j++){
  168.         if( i>1 && i<17 && j>4 && j<11)
  169.           out_image[i][j] = 200;
  170.     }
  171.    }
  172.  
  173.  
  174.       /*  make a rectangle with a hole in it */
  175.    for(i=0; i<ROWS; i++){
  176.       for(j=0; j<COLS; j++){
  177.         if( i>=5 && i<=8 && j>=5 && j<=18)
  178.           out_image[i][j] = 200;
  179.     }
  180.    }
  181.    for(i=0; i<ROWS; i++){
  182.       for(j=0; j<COLS; j++){
  183.         if( i>=15 && i<=18 && j>=5 && j<=18)
  184.           out_image[i][j] = 200;
  185.     }
  186.    }
  187.    for(i=0; i<ROWS; i++){
  188.       for(j=0; j<COLS; j++){
  189.         if( j>=5 && j<=8 && i>=5 && i<=18)
  190.           out_image[i][j] = 200;
  191.     }
  192.    }
  193.    for(i=0; i<ROWS; i++){
  194.       for(j=0; j<COLS; j++){
  195.         if( j>=15 && j<=18 && i>=5 && i<=18)
  196.           out_image[i][j] = 200;
  197.     }
  198.    }
  199.  
  200.      /* make the entire area white with a black hole
  201.      in it good for interior outline */
  202.    for(i=0; i<ROWS; i++){
  203.       for(j=0; j<COLS; j++){
  204.          if( i>=10 && i<=15 && j>=10 && j<=18)
  205.             out_image[i][j] = 0;
  206.          else
  207.             out_image[i][j] = 200;
  208.       }
  209.    }
  210.  
  211.  
  212.       /* make a square  */
  213.    for(i=0; i<ROWS; i++){
  214.       for(j=0; j<COLS; j++){
  215.          if( i>=8 && i<=18 && j>=8 && j<=18)
  216.             out_image[i][j] = 200;
  217.          else
  218.             out_image[i][j] = 0;
  219.       }
  220.    }
  221.  
  222.       /* make a square  with a hole in
  223.         it for closing practice */
  224.    for(i=0; i<ROWS; i++){
  225.       for(j=0; j<COLS; j++){
  226.          if( i>=8 && i<=13 && j>=8 && j<=13)
  227.             out_image[i][j] = 200;
  228.          else
  229.             out_image[i][j] = 0;
  230.       }
  231.    }
  232.    out_image[10][10] = 0;
  233.    out_image[11][10] = 0;
  234.  
  235.       /* make 2 small squares
  236.         illustrate closing and special closing */
  237.    for(i=0; i<ROWS; i++)
  238.       for(j=0; j<COLS; j++)
  239.          out_image[i][j] = 0;
  240.    for(i=0; i<ROWS; i++){
  241.       for(j=0; j<COLS; j++){
  242.          if( i>=8 && i<=13 && j>=8 && j<=9)
  243.             out_image[i][j] = 200;
  244.          if( i>=8 && i<=13 && j>=11 && j<=13)
  245.             out_image[i][j] = 200;
  246.       }
  247.    }
  248.  
  249.       /* make a rectangle  */
  250.    for(i=0; i<ROWS; i++){
  251.       for(j=0; j<COLS; j++){
  252.          if( i>=8 && i<=18 && j>=4 && j<=18)
  253.             out_image[i][j] = 200;
  254.          else
  255.             out_image[i][j] = 0;
  256.       }
  257.    }
  258.  
  259.       /* make a block letter A */
  260.    for(i=0; i<ROWS; i++)
  261.       for(j=0; j<COLS; j++)
  262.          out_image[i][j] = 0;
  263.    for(i=0; i<ROWS; i++)
  264.       for(j=0; j<COLS; j++)
  265.          if(i>=10 && i<=20 && j>=10 && j<=50)
  266.           out_image[i][j] = 200;
  267.    for(i=0; i<ROWS; i++)
  268.       for(j=0; j<COLS; j++)
  269.          if(i>=40 && i<=50 && j>=10 && j<=50)
  270.           out_image[i][j] = 200;
  271.    for(i=0; i<ROWS; i++)
  272.       for(j=0; j<COLS; j++)
  273.          if(i>=10 && i<=90 && j>=10 && j<=20)
  274.           out_image[i][j] = 200;
  275.    for(i=0; i<ROWS; i++)
  276.       for(j=0; j<COLS; j++)
  277.          if(i>=10 && i<=90 && j>=40 && j<=50)
  278.           out_image[i][j] = 200;
  279.  
  280.       /* make a broken line */
  281.    for(i=0; i<ROWS; i++)
  282.       for(j=0; j<COLS; j++)
  283.          out_image[i][j] = 0;
  284.    for(i=0; i<ROWS; i++)
  285.       for(j=0; j<COLS; j++)
  286.          if(i>=10 && i<=11 && j>=5 && j<=18)
  287.           out_image[i][j] = 200;
  288.    out_image[10][11] = 0;
  289.    out_image[11][11] = 0;
  290.  
  291.  
  292.       /* make two squares joined together */
  293.    for(i=0; i<ROWS; i++)
  294.       for(j=0; j<COLS; j++)
  295.          out_image[i][j] = 0;
  296.    for(i=0; i<ROWS; i++){
  297.       for(j=0; j<COLS; j++){
  298.          if( i>=5 && i<=15 && j>=5 && j<=9)
  299.             out_image[i][j] = 200;
  300.          if( i>=5 && i<=15 && j>=12 && j<=17)
  301.             out_image[i][j] = 200;
  302.       }
  303.    }
  304.    out_image[10][10] = 200;
  305.    out_image[10][11] = 200;
  306.  
  307.  
  308.  
  309.  
  310.    /* make a texture, checkerboard of 100-200
  311.       with each square the size given by the 
  312.       variable square_size 
  313.       I'll do this a little different and let
  314.       the user specify the square size as the
  315.       last parameter on the line. */
  316.  
  317.    sqaure_size = atoi(argv[4]);
  318.    ii=0; 
  319.    jj=0; 
  320.    set_i=0; 
  321.    set_j